// stores/categoryStore.ts
import { ref } from 'vue';
import { defineStore } from 'pinia';

export const useCategoryStore = defineStore('category', () => {
  const selectedCategory = ref<object | null>(null);  // 当前选中的分类对象

  // 设置选中的分类
  function setCategory(category: object) {
    selectedCategory.value = category;
  }

  // 清除选中的分类
  function clearCategory() {
    selectedCategory.value = null;
  }

  return { selectedCategory, setCategory, clearCategory };
});


export const useSearchStore = defineStore('search', () => {
  const searchText = ref<string>('');  // 当前的搜索关键词
  const isLoading = ref<boolean>(false);  // 控制加载状态

  // 设置搜索关键词
  function setSearchText(text: string) {
    searchText.value = text;
  }

  // 清除搜索关键词和结果
  function clearSearch() {
    searchText.value = '';
  }

  return { searchText, isLoading, setSearchText, clearSearch };
});